package com.lolineet.auth.token;

import com.lolineet.auth.entity.SysUsernamePasswordLoginEntity;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * UsernamePasswordAuth
 *
 * @author YUKI.N
 * @version 1.0
 * @description
 * @date 2025/4/17 17:26
 */
public class SysUsernamePasswordAuthToken extends AbstractAuthenticationToken {
    private final Object entity;

    private final String password;

    public SysUsernamePasswordAuthToken(Object entity, String password) {
        super(null);
        this.entity = entity;
        this.password = password;
        setAuthenticated(false);
    }

    public SysUsernamePasswordAuthToken(Collection<? extends GrantedAuthority> authorities, SysUsernamePasswordLoginEntity entity, String password) {
        super(authorities);
        this.entity = entity;
        this.password = password;
        setAuthenticated(true);
    }

    @Override
    public Object getCredentials() {
        return password;
    }

    @Override
    public Object getPrincipal() {
        return entity;
    }
}
